lm2b=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk2 ) #This code is new, eliminated unused predictors
summary(lm2b)
print(paste("D.F.:",lm2b$degree.freedom))
install.packages("robustbase")
#Replication code for Shunko et al. (2018) MS Replication Project
#March 14, 2022
####
#Most code is copied from original R script included in the supplementary materials to the original article, except where indicated
###
print("##########BEGIN PRINTING RESULTS###########")
data1=read.csv("replication_data.csv") #this is the code for replication data
#Count of Observations
print("COUNT OF OBSERVATIONS:")
countData=subset(data1,cNumber==1)
table(countData$Structure,countData$Visibility,countData$Incentives,countData$Population,countData$Location) #edited to include location
#Permutation Tests
print("PERMUTATION TESTS:")
library(plyr)
library(dplyr)
library(boot)
my_quantile=function(temp,i){
return(c(quantile(temp[i],probs=c(.25,.5,.75),na.rm=T)));
}
my_permutation_tests=function(sample1,sample2){
ns1=length(sample1)
ns2=length(sample2)
n=ns1+ns2
all=c(sample1,sample2)
original3=quantile(sample1,.25,na.rm=T)-quantile(sample2,.25,na.rm=T)
original4=quantile(sample1,.5,na.rm=T)-quantile(sample2,.5,na.rm=T)
original5=quantile(sample1,.75,na.rm=T)-quantile(sample2,.75,na.rm=T)
stat_dist3=NULL
stat_dist4=NULL
stat_dist5=NULL
for(i in 1:10000){
pick1=sample(1:n,size=ns1,replace=FALSE)
pick2=setdiff(1:n,pick1)
s1=all[pick1]
s2=all[pick2]
st3=quantile(s1,.25,na.rm=T)-quantile(s2,.25,na.rm=T)
st4=quantile(s1,.5,na.rm=T)-quantile(s2,.5,na.rm=T)
st5=quantile(s1,.75,na.rm=T)-quantile(s2,.75,na.rm=T)
stat_dist3=c(stat_dist3,st3)
stat_dist4=c(stat_dist4,st4)
stat_dist5=c(stat_dist5,st5)
}
prob_left3=(sum(stat_dist3<=original3)+1)/10001
prob_right3=(sum(stat_dist3>=original3)+1)/10001
prob_left4=(sum(stat_dist4<=original4)+1)/10001
prob_right4=(sum(stat_dist4>=original4)+1)/10001
prob_left5=(sum(stat_dist5<=original5)+1)/10001
prob_right5=(sum(stat_dist5>=original5)+1)/10001
return(c(prob_left3,prob_left4,prob_left5,prob_right3,prob_right4,prob_right5))
}
merged_data_high=subset(data1,cNumber==1)
moments=c("25th perc.","50th perc.","75th perc.")
#####################
#We revised the permutation test code from the original R script to accommodate only the conditions we need.
#Note: numbers vary slightly each time due to the bootstrapping process
######################
##UW Madison
temp_sample1=subset(merged_data_high,Structure=="Parallel" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
temp_sample2=subset(merged_data_high,Structure=="Single" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
tests=my_permutation_tests(temp_sample1,temp_sample2)
res1=boot(data=temp_sample1,R=1000,statistic=my_quantile)
res2=boot(data=temp_sample2,R=1000,statistic=my_quantile)
print("Parallel vs. Single at UW Madison") #This code is new
for(i in 1:3){
temp_string="";
if(res1$t0[i]>res2$t0[i]){
print(paste(round(res1$t0[i],2),">",round(res2$t0[i],2)," p-value=",round(tests[3+i],3)))
}else{
print(paste(round(res1$t0[i],2),"<",round(res2$t0[i],2)," p-value=",round(tests[i],3)))
}
}
#getting the standard errors
temp_sample=subset(merged_data_high,Structure=="Parallel" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("parallel at UWMadison")
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
temp_sample=subset(merged_data_high,Structure=="Single" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("single at UWMadison") #This code is new
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
###########USC
temp_sample1=subset(merged_data_high,Structure=="Parallel" & Location == "USC")$MEDIAN_SPEED #This code is new
temp_sample2=subset(merged_data_high,Structure=="Single" & Location == "USC")$MEDIAN_SPEED #This code is new
tests=my_permutation_tests(temp_sample1,temp_sample2)
res1=boot(data=temp_sample1,R=1000,statistic=my_quantile)
res2=boot(data=temp_sample2,R=1000,statistic=my_quantile)
print("Parallel vs. Single at USC") #This code is new
for(i in 1:3){
temp_string="";
if(res1$t0[i]>res2$t0[i]){
print(paste(round(res1$t0[i],2),">",round(res2$t0[i],2)," p-value=",round(tests[3+i],3)))
}else{
print(paste(round(res1$t0[i],2),"<",round(res2$t0[i],2)," p-value=",round(tests[i],3)))
}
}
#getting the standard errors
temp_sample=subset(merged_data_high,Structure=="Parallel" & Location == "USC")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("parallel at USC")
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
temp_sample=subset(merged_data_high,Structure=="Single" & Location == "USC")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("single at USC") #This code is new
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
#########
#Next, we adapt the original R code for robust regression analysis to accommodate the reduced number of conditions
########
library(robustbase)
merged_data_high=subset(data1,cNumber==1)
regression_data=subset(merged_data_high,GENDER!="NoResponse")
regression_data$GENDER=as.factor(as.character(regression_data$GENDER))
regression_data$Structure=as.factor(as.character(regression_data$Structure))
regression_data$Structure=relevel(regression_data$Structure,ref="Single")
# Robust Regression on M-Turk DATA - UW-Madison
print("regression results for UW Madison") #This code is new
regression_data_mturk=subset(regression_data, Population=="M.Turk" & Location == "UWMadison") #This code is new
lm2=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk ) #This code is new, eliminated unused predictors
summary(lm2)
print(paste("D.F.:",lm2$degree.freedom))
# Robust Regression on M-Turk DATA - USC
print("regression results for USC") #This code is new
regression_data_mturk2=subset(regression_data, Population=="M.Turk" & Location == "USC") #This code is new
lm2b=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk2 ) #This code is new, eliminated unused predictors
summary(lm2b)
print(paste("D.F.:",lm2b$degree.freedom))
#Replication code for Shunko et al. (2018) MS Replication Project
#March 14, 2022
####
#Most code is copied from original R script included in the supplementary materials to the original article, except where indicated
###
print("##########BEGIN PRINTING RESULTS###########")
data1=read.csv("replication_data.csv") #this is the code for replication data
#Count of Observations
print("COUNT OF OBSERVATIONS:")
countData=subset(data1,cNumber==1)
table(countData$Structure,countData$Visibility,countData$Incentives,countData$Population,countData$Location) #edited to include location
# Install and load necessary packages
#install.packages("sqldf") # Used to read in DUSMCPUB file
#install.packages("dplyr") # Used for tidy data management
library(sqldf)
# Install and load necessary packages
#install.packages("sqldf") # Used to read in DUSMCPUB file
#install.packages("dplyr") # Used for tidy data management
library(sqldf)
library(dplyr)
#Increase memory limit to make space for large file
# memory.limit()
#memory.limit(size=20000)
# Create dataframe containing variables for column width, name, and end position
columns <- data.frame(widths=c(19,1,40,2,1,1,2,2,1,4,1,2,2,2,2,1,1,1,16,4,1,1,1,
1,34,1,1,4,3,1,3,3,2,1,2,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,36,2,1,5,5,5,5,5,5,5,5,5,5,5,5,5,
5,5,5,5,5,5,5,1,2,1,1,1,1,33,3,1,1,2,315,4,2,4,2))
columns$names <- c("blank1", # tape locations 1-19
"Resident_Status_US",  # tape location 20
"blank2",
"Education_1989",
"Education_2003",
"Education_flag",
"Month_of_Death",
"blank3",
"Sex",
"DetailAge",
"Age_Substitution_Flag",
"Age_Recode_52",
"Age_Recode_27",
"Age_Recode_12",
"Infant_Age_Recode_22",
"Place_of_Death_and_Status",
"Marital_Status",
"Day_of_Week_of_Death",
"blank4",
"Current_Data_Year",
"Injury_at_Work",
"Manner_of_Death",
"Method_of_Disposition",
"Autopsy",
"blank5",
"Activity_Code",
"Place_of_Injury",
"ICD_Code_10",
"Cause_Recode_358",
"blank6",
"Cause_Recode_113",
"Infant_Cause_Recode_130",
"Cause_Recode_39",
"blank7",
"Number_Entity_Axis_Conditions",
"Condition_1EA", "Condition_2EA", "Condition_3EA", "Condition_4EA", "Condition_5EA",
"Condition_6EA", "Condition_7EA", "Condition_8EA", "Condition_9EA", "Condition_10EA",
"Condition_11EA", "Condition_12EA", "Condition_13EA", "Condition_14EA", "Condition_15EA",
"Condition_16EA", "Condition_17EA", "Condition_18EA", "Condition_19EA", "Condition_20EA",
"blank8",
"Number_Record_Axis_Conditions",
"blank9",
"Condition_1RA", "Condition_2RA", "Condition_3RA", "Condition_4RA", "Condition_5RA",
"Condition_6RA", "Condition_7RA", "Condition_8RA", "Condition_9RA", "Condition_10RA",
"Condition_11RA", "Condition_12RA", "Condition_13RA", "Condition_14RA", "Condition_15RA",
"Condition_16RA", "Condition_17RA", "Condition_18RA", "Condition_19RA", "Condition_20RA",
"blank10",
"Race",
"Bridged_Race_Flag",
"Race_Imputation_Flag",
"Race_Recode_3",
"Race_Recode_5",
"blank11",
"Hispanic_Origin",
"blank12",
"Hispanic_Origin_9_Race_Recode",
"Race_Recode_40",
"blank13",
"CensusOcc",
"Occ_26",
"CensusInd",
"Ind_23")
# Read in file using parameters from 'columns' dataframe
mort2020<- read.fwf("VS20MORT.DUSMCPUB_r20220105", widths=columns$widths, stringsAsFactors=F)
# Install and load necessary packages
#install.packages("sqldf") # Used to read in DUSMCPUB file
#install.packages("dplyr") # Used for tidy data management
library(sqldf)
library(dplyr)
#March 14, 2022
####
#Most code is copied from original R script included in the supplementary materials to the original article, except where indicated
###
print("##########BEGIN PRINTING RESULTS###########")
data1=read.csv("replication_data.csv") #this is the code for replication data
#Count of Observations
print("COUNT OF OBSERVATIONS:")
countData=subset(data1,cNumber==1)
table(countData$Structure,countData$Visibility,countData$Incentives,countData$Population,countData$Location) #edited to include location
print("##########BEGIN PRINTING RESULTS###########")
#Replication code for Shunko et al. (2018) MS Replication Project
#March 14, 2022
####
#Most code is copied from original R script included in the supplementary materials to the original article, except where indicated
###
print("##########BEGIN PRINTING RESULTS###########")
data1=read.csv("replication_data.csv") #this is the code for replication data
#Count of Observations
print("COUNT OF OBSERVATIONS:")
countData=subset(data1,cNumber==1)
table(countData$Structure,countData$Visibility,countData$Incentives,countData$Population,countData$Location) #edited to include location
#Permutation Tests
print("PERMUTATION TESTS:")
library(plyr)
library(dplyr)
library(boot)
my_quantile=function(temp,i){
return(c(quantile(temp[i],probs=c(.25,.5,.75),na.rm=T)));
}
my_permutation_tests=function(sample1,sample2){
ns1=length(sample1)
ns2=length(sample2)
n=ns1+ns2
all=c(sample1,sample2)
original3=quantile(sample1,.25,na.rm=T)-quantile(sample2,.25,na.rm=T)
original4=quantile(sample1,.5,na.rm=T)-quantile(sample2,.5,na.rm=T)
original5=quantile(sample1,.75,na.rm=T)-quantile(sample2,.75,na.rm=T)
stat_dist3=NULL
stat_dist4=NULL
stat_dist5=NULL
for(i in 1:10000){
pick1=sample(1:n,size=ns1,replace=FALSE)
pick2=setdiff(1:n,pick1)
s1=all[pick1]
s2=all[pick2]
st3=quantile(s1,.25,na.rm=T)-quantile(s2,.25,na.rm=T)
st4=quantile(s1,.5,na.rm=T)-quantile(s2,.5,na.rm=T)
st5=quantile(s1,.75,na.rm=T)-quantile(s2,.75,na.rm=T)
stat_dist3=c(stat_dist3,st3)
stat_dist4=c(stat_dist4,st4)
stat_dist5=c(stat_dist5,st5)
}
prob_left3=(sum(stat_dist3<=original3)+1)/10001
prob_right3=(sum(stat_dist3>=original3)+1)/10001
prob_left4=(sum(stat_dist4<=original4)+1)/10001
prob_right4=(sum(stat_dist4>=original4)+1)/10001
prob_left5=(sum(stat_dist5<=original5)+1)/10001
prob_right5=(sum(stat_dist5>=original5)+1)/10001
return(c(prob_left3,prob_left4,prob_left5,prob_right3,prob_right4,prob_right5))
}
merged_data_high=subset(data1,cNumber==1)
moments=c("25th perc.","50th perc.","75th perc.")
#####################
#We revised the permutation test code from the original R script to accommodate only the conditions we need.
#Note: numbers vary slightly each time due to the bootstrapping process
######################
##UW Madison
temp_sample1=subset(merged_data_high,Structure=="Parallel" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
temp_sample2=subset(merged_data_high,Structure=="Single" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
tests=my_permutation_tests(temp_sample1,temp_sample2)
res1=boot(data=temp_sample1,R=1000,statistic=my_quantile)
res2=boot(data=temp_sample2,R=1000,statistic=my_quantile)
print("Parallel vs. Single at UW Madison") #This code is new
for(i in 1:3){
temp_string="";
if(res1$t0[i]>res2$t0[i]){
print(paste(round(res1$t0[i],2),">",round(res2$t0[i],2)," p-value=",round(tests[3+i],3)))
}else{
print(paste(round(res1$t0[i],2),"<",round(res2$t0[i],2)," p-value=",round(tests[i],3)))
}
}
#getting the standard errors
temp_sample=subset(merged_data_high,Structure=="Parallel" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("parallel at UWMadison")
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
temp_sample=subset(merged_data_high,Structure=="Single" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("single at UWMadison") #This code is new
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
###########USC
temp_sample1=subset(merged_data_high,Structure=="Parallel" & Location == "USC")$MEDIAN_SPEED #This code is new
temp_sample2=subset(merged_data_high,Structure=="Single" & Location == "USC")$MEDIAN_SPEED #This code is new
tests=my_permutation_tests(temp_sample1,temp_sample2)
res1=boot(data=temp_sample1,R=1000,statistic=my_quantile)
res2=boot(data=temp_sample2,R=1000,statistic=my_quantile)
print("Parallel vs. Single at USC") #This code is new
for(i in 1:3){
temp_string="";
if(res1$t0[i]>res2$t0[i]){
print(paste(round(res1$t0[i],2),">",round(res2$t0[i],2)," p-value=",round(tests[3+i],3)))
}else{
print(paste(round(res1$t0[i],2),"<",round(res2$t0[i],2)," p-value=",round(tests[i],3)))
}
}
#getting the standard errors
temp_sample=subset(merged_data_high,Structure=="Parallel" & Location == "USC")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("parallel at USC")
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
temp_sample=subset(merged_data_high,Structure=="Single" & Location == "USC")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("single at USC") #This code is new
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
#########
#Next, we adapt the original R code for robust regression analysis to accommodate the reduced number of conditions
########
library(robustbase)
merged_data_high=subset(data1,cNumber==1)
regression_data=subset(merged_data_high,GENDER!="NoResponse")
regression_data$GENDER=as.factor(as.character(regression_data$GENDER))
regression_data$Structure=as.factor(as.character(regression_data$Structure))
regression_data$Structure=relevel(regression_data$Structure,ref="Single")
# Robust Regression on M-Turk DATA - UW-Madison
print("regression results for UW Madison") #This code is new
regression_data_mturk=subset(regression_data, Population=="M.Turk" & Location == "UWMadison") #This code is new
lm2=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk ) #This code is new, eliminated unused predictors
summary(lm2)
print(paste("D.F.:",lm2$degree.freedom))
# Robust Regression on M-Turk DATA - USC
print("regression results for USC") #This code is new
regression_data_mturk2=subset(regression_data, Population=="M.Turk" & Location == "USC") #This code is new
lm2b=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk2 ) #This code is new, eliminated unused predictors
summary(lm2b)
print(paste("D.F.:",lm2b$degree.freedom))
print("##########BEGIN PRINTING RESULTS###########")
#Replication code for Shunko et al. (2018) MS Replication Project
#March 14, 2022
####
#Most code is copied from original R script included in the supplementary materials to the original article, except where indicated
###
print("##########BEGIN PRINTING RESULTS###########")
data1=read.csv("replication_data.csv") #this is the code for replication data
#Count of Observations
print("COUNT OF OBSERVATIONS:")
countData=subset(data1,cNumber==1)
table(countData$Structure,countData$Visibility,countData$Incentives,countData$Population,countData$Location) #edited to include location
#Permutation Tests
print("PERMUTATION TESTS:")
library(plyr)
library(dplyr)
library(boot)
my_quantile=function(temp,i){
return(c(quantile(temp[i],probs=c(.25,.5,.75),na.rm=T)));
}
my_permutation_tests=function(sample1,sample2){
ns1=length(sample1)
ns2=length(sample2)
n=ns1+ns2
all=c(sample1,sample2)
original3=quantile(sample1,.25,na.rm=T)-quantile(sample2,.25,na.rm=T)
original4=quantile(sample1,.5,na.rm=T)-quantile(sample2,.5,na.rm=T)
original5=quantile(sample1,.75,na.rm=T)-quantile(sample2,.75,na.rm=T)
stat_dist3=NULL
stat_dist4=NULL
stat_dist5=NULL
for(i in 1:10000){
pick1=sample(1:n,size=ns1,replace=FALSE)
pick2=setdiff(1:n,pick1)
s1=all[pick1]
s2=all[pick2]
st3=quantile(s1,.25,na.rm=T)-quantile(s2,.25,na.rm=T)
st4=quantile(s1,.5,na.rm=T)-quantile(s2,.5,na.rm=T)
st5=quantile(s1,.75,na.rm=T)-quantile(s2,.75,na.rm=T)
stat_dist3=c(stat_dist3,st3)
stat_dist4=c(stat_dist4,st4)
stat_dist5=c(stat_dist5,st5)
}
prob_left3=(sum(stat_dist3<=original3)+1)/10001
prob_right3=(sum(stat_dist3>=original3)+1)/10001
prob_left4=(sum(stat_dist4<=original4)+1)/10001
prob_right4=(sum(stat_dist4>=original4)+1)/10001
prob_left5=(sum(stat_dist5<=original5)+1)/10001
prob_right5=(sum(stat_dist5>=original5)+1)/10001
return(c(prob_left3,prob_left4,prob_left5,prob_right3,prob_right4,prob_right5))
}
merged_data_high=subset(data1,cNumber==1)
moments=c("25th perc.","50th perc.","75th perc.")
#####################
#We revised the permutation test code from the original R script to accommodate only the conditions we need.
#Note: numbers vary slightly each time due to the bootstrapping process
######################
##UW Madison
temp_sample1=subset(merged_data_high,Structure=="Parallel" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
temp_sample2=subset(merged_data_high,Structure=="Single" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
tests=my_permutation_tests(temp_sample1,temp_sample2)
res1=boot(data=temp_sample1,R=1000,statistic=my_quantile)
res2=boot(data=temp_sample2,R=1000,statistic=my_quantile)
print("Parallel vs. Single at UW Madison") #This code is new
for(i in 1:3){
temp_string="";
if(res1$t0[i]>res2$t0[i]){
print(paste(round(res1$t0[i],2),">",round(res2$t0[i],2)," p-value=",round(tests[3+i],3)))
}else{
print(paste(round(res1$t0[i],2),"<",round(res2$t0[i],2)," p-value=",round(tests[i],3)))
}
}
#getting the standard errors
temp_sample=subset(merged_data_high,Structure=="Parallel" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("parallel at UWMadison")
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
temp_sample=subset(merged_data_high,Structure=="Single" & Location == "UWMadison")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("single at UWMadison") #This code is new
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
###########USC
temp_sample1=subset(merged_data_high,Structure=="Parallel" & Location == "USC")$MEDIAN_SPEED #This code is new
temp_sample2=subset(merged_data_high,Structure=="Single" & Location == "USC")$MEDIAN_SPEED #This code is new
tests=my_permutation_tests(temp_sample1,temp_sample2)
res1=boot(data=temp_sample1,R=1000,statistic=my_quantile)
res2=boot(data=temp_sample2,R=1000,statistic=my_quantile)
print("Parallel vs. Single at USC") #This code is new
for(i in 1:3){
temp_string="";
if(res1$t0[i]>res2$t0[i]){
print(paste(round(res1$t0[i],2),">",round(res2$t0[i],2)," p-value=",round(tests[3+i],3)))
}else{
print(paste(round(res1$t0[i],2),"<",round(res2$t0[i],2)," p-value=",round(tests[i],3)))
}
}
#getting the standard errors
temp_sample=subset(merged_data_high,Structure=="Parallel" & Location == "USC")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("parallel at USC")
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
temp_sample=subset(merged_data_high,Structure=="Single" & Location == "USC")$MEDIAN_SPEED #This code is new
res=boot(data=temp_sample,R=1000,statistic=my_quantile)
print("single at USC") #This code is new
for(i in 1:3){
print(paste(moments[i],round(res$t0[i],2),"(",round(sd(res$t[,i]),2),")"))
}
#########
#Next, we adapt the original R code for robust regression analysis to accommodate the reduced number of conditions
########
library(robustbase)
merged_data_high=subset(data1,cNumber==1)
regression_data=subset(merged_data_high,GENDER!="NoResponse")
regression_data$GENDER=as.factor(as.character(regression_data$GENDER))
regression_data$Structure=as.factor(as.character(regression_data$Structure))
regression_data$Structure=relevel(regression_data$Structure,ref="Single")
# Robust Regression on M-Turk DATA - UW-Madison
print("regression results for UW Madison") #This code is new
regression_data_mturk=subset(regression_data, Population=="M.Turk" & Location == "UWMadison") #This code is new
lm2=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk ) #This code is new, eliminated unused predictors
summary(lm2)
print(paste("D.F.:",lm2$degree.freedom))
# Robust Regression on M-Turk DATA - USC
print("regression results for USC") #This code is new
regression_data_mturk2=subset(regression_data, Population=="M.Turk" & Location == "USC") #This code is new
lm2b=lmrob(MEDIAN_SPEED~Structure+AGE_1990+GENDER+MANAGERIAL+DEVICE, data=regression_data_mturk2 ) #This code is new, eliminated unused predictors
summary(lm2b)
print(paste("D.F.:",lm2b$degree.freedom))
